package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IdleAffiliateCpaIncomeDetail;
import com.ruoyi.system.service.IIdleAffiliateCpaIncomeDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 闲鱼联盟CPA收入明细Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/cpa")
public class IdleAffiliateCpaIncomeDetailController extends BaseController
{
    @Autowired
    private IIdleAffiliateCpaIncomeDetailService idleAffiliateCpaIncomeDetailService;

    /**
     * 查询闲鱼联盟CPA收入明细列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(IdleAffiliateCpaIncomeDetail idleAffiliateCpaIncomeDetail)
    {
        startPage();
        List<IdleAffiliateCpaIncomeDetail> list = idleAffiliateCpaIncomeDetailService.selectIdleAffiliateCpaIncomeDetailList(idleAffiliateCpaIncomeDetail);
        return getDataTable(list);
    }

    /**
     * 导出闲鱼联盟CPA收入明细列表
     */
    @Anonymous
    @Log(title = "闲鱼联盟CPA收入明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IdleAffiliateCpaIncomeDetail idleAffiliateCpaIncomeDetail)
    {
        List<IdleAffiliateCpaIncomeDetail> list = idleAffiliateCpaIncomeDetailService.selectIdleAffiliateCpaIncomeDetailList(idleAffiliateCpaIncomeDetail);
        ExcelUtil<IdleAffiliateCpaIncomeDetail> util = new ExcelUtil<IdleAffiliateCpaIncomeDetail>(IdleAffiliateCpaIncomeDetail.class);
        util.exportExcel(response, list, "闲鱼联盟CPA收入明细数据");
    }

    /**
     * 获取闲鱼联盟CPA收入明细详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(idleAffiliateCpaIncomeDetailService.selectIdleAffiliateCpaIncomeDetailById(id));
    }

    /**
     * 新增闲鱼联盟CPA收入明细
     */
    @Anonymous
    @Log(title = "闲鱼联盟CPA收入明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IdleAffiliateCpaIncomeDetail idleAffiliateCpaIncomeDetail)
    {
        return toAjax(idleAffiliateCpaIncomeDetailService.insertIdleAffiliateCpaIncomeDetail(idleAffiliateCpaIncomeDetail));
    }

    /**
     * 修改闲鱼联盟CPA收入明细
     */
    @Anonymous
    @Log(title = "闲鱼联盟CPA收入明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IdleAffiliateCpaIncomeDetail idleAffiliateCpaIncomeDetail)
    {
        return toAjax(idleAffiliateCpaIncomeDetailService.updateIdleAffiliateCpaIncomeDetail(idleAffiliateCpaIncomeDetail));
    }

    /**
     * 删除闲鱼联盟CPA收入明细
     */
    @Anonymous
    @Log(title = "闲鱼联盟CPA收入明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(idleAffiliateCpaIncomeDetailService.deleteIdleAffiliateCpaIncomeDetailByIds(ids));
    }

    /**
     * 根据账单ID获取闲鱼联盟CPA收入明细详细信息
     */
    @Anonymous
    @GetMapping(value = "/bill/{billId}")
    public AjaxResult getInfoByBillId(@PathVariable("billId") String billId)
    {
        return success(idleAffiliateCpaIncomeDetailService.selectIdleAffiliateCpaIncomeDetailByBillId(billId));
    }

    /**
     * 根据子发布者ID获取闲鱼联盟CPA收入明细详细信息
     */
    @Anonymous
    @GetMapping(value = "/publisher/{subPublisherId}")
    public AjaxResult getInfoBySubPublisherId(@PathVariable("subPublisherId") String subPublisherId)
    {
        return success(idleAffiliateCpaIncomeDetailService.selectIdleAffiliateCpaIncomeDetailBySubPublisherId(subPublisherId));
    }

    /**
     * 根据被邀请者ID获取闲鱼联盟CPA收入明细详细信息
     */
    @Anonymous
    @GetMapping(value = "/invitee/{inviteeId}")
    public AjaxResult getInfoByInviteeId(@PathVariable("inviteeId") String inviteeId)
    {
        return success(idleAffiliateCpaIncomeDetailService.selectIdleAffiliateCpaIncomeDetailByInviteeId(inviteeId));
    }

    /**
     * 根据活动ID获取闲鱼联盟CPA收入明细详细信息
     */
    @Anonymous
    @GetMapping(value = "/campaign/{campaignId}")
    public AjaxResult getInfoByCampaignId(@PathVariable("campaignId") String campaignId)
    {
        return success(idleAffiliateCpaIncomeDetailService.selectIdleAffiliateCpaIncomeDetailByCampaignId(campaignId));
    }

    /**
     * 获取CPA收入明细统计信息
     */
    @Anonymous
    @GetMapping("/statistics")
    public AjaxResult getStatistics()
    {
        return success(idleAffiliateCpaIncomeDetailService.getCpaIncomeStatistics());
    }
} 